import threading
import time
import requests
import os
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

url_list = [
    ('黄玉瑶的作品1.mp4', 'https://v26-web.douyinvod.com/5f7a244da0d3958cd13bffe143829811/646c6103/video/tos/cn/tos-cn-ve-15c001-alinc2/osD9nDgvQlkgEvAlIBYgNCeIKb20cAbDO1Afjq/?a=6383&ch=0&cr=0&dr=0&er=0&cd=0%7C0%7C0%7C0&cv=1&br=1692&bt=1692&cs=0&ds=3&ft=GN7rKGVVywtiRFd8jmo~ySqTeaApSa7g6vrK-wK8D2o0g3&mime_type=video_mp4&qs=0&rc=Zmk7aWdpaGQ1PGZmNjVlZ0Bpajl4PDo6ZnQ2azMzNGkzM0BfNTJhMjZfNmAxY18xMF81YSNxMV42cjRnZWpgLS1kLS9zcw%3D%3D&l=2023052313450348B1B3C3EC0F0C68480C&btag=e00010000'),
    ('黄玉瑶的作品2.mp4', 'https://v26-web.douyinvod.com/a9198d48f28e2550d7637c8b63524312/646c6126/video/tos/cn/tos-cn-ve-15c001-alinc2/oYtAABDThpnG9LgPQ3rze8qAbHCg9joAaYQcLf/?a=6383&ch=0&cr=0&dr=0&er=0&cd=0%7C0%7C0%7C0&cv=1&br=2402&bt=2402&cs=0&ds=6&ft=GN7rKGVVywtiRFd8jmo~ySqTeaApk17g6vrK-wK8D2o0g3&mime_type=video_mp4&qs=0&rc=PDtmOTQ6NDc7Z2loNjxlZ0BpMzprczY6ZjptaDMzNGkzM0AtYF8yM15hNi4xLWBgLzViYSNkZ2FxcjQwNW5gLS1kLS9zcw%3D%3D&l=20230523134547F2577C5974F6655742E0&btag=e00008000'),
    ('忆菁很无敌的作品.mp4', 'https://v26-web.douyinvod.com/a43e2a073f31ac2b65f9821e96512e2c/646c6255/video/tos/cn/tos-cn-ve-15c001-alinc2/oQCBN5hAFhxBB3yLQdpeFgPfA2AisQiygIxEzE/?a=6383&ch=0&cr=0&dr=0&er=0&cd=0%7C0%7C0%7C0&cv=1&br=873&bt=873&cs=0&ds=3&ft=GN7rKGVVywtiRFd8jmo~ySqTeaApC17g6vrK-wK8D2o0g3&mime_type=video_mp4&qs=0&rc=OztlZTtpM2g7OThmZzs1OEBpanA6cmw5cjM2azMzNGkzM0AyMTEwXzZeNi0xXy8wMTA1YSNsNGJvMmQ0c2pgLS1kLS9zcw%3D%3D&l=202305231346246C2343564B6FC65B72AB&btag=e00030000')
]

def task(file_name, video_url):
    res = requests.get(video_url)
    file_path = os.path.join(base_path, 'files', file_name)
    with open(file_path, mode='wb') as f:
        f.write(res.content)
    print(time.time())

for name, url in url_list:
    # 创建线程，让每个线程都去执行task函数（参数不同）
    t = threading.Thread(target=task, args=(name, url))
    t.start()
